﻿//2009-12-15    判斷使用者權限（CheckUser）                By Victor
//2010-03-02    修改使用者認證（CheckUser->UserAuth)       By Victor
//2010-05-17    新增查詢案場使用者清單                     By 應翰

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

//Using Namespace
using System.Data;
using System.Data.SqlClient;

namespace DataAccess
{
    public class UserSet
    {
        string strSQL;
        DataTable dtTemp;
        string strUpdateTime = DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss");

        //使用者資料相關    相關Table：WebUser
        #region public DataTable QueryAllUser()        //查詢全部使用者清單     By Victor
        /// <summary>
        /// 查詢全部使用者清單 
        /// </summary>
        /// <returns>回傳全部使用者相關資料</returns>
        public DataTable QueryAllUser()
        {
            try
            {
                strSQL = "Select * From WebUser";
                return new CommonFun().GenDataTable(strSQL);
            }
            catch(Exception ex)
            {
                new CommonFun().AddErrorMsg("QueryAllUser", ex.ToString(), strSQL);
                return null;
            }
        }
        #endregion

        #region public DataTable QueryUserByID(string strUserID)        //查詢單一使用者清單     By Victor
        /// <summary>
        /// 查詢單一使用者清單 
        /// </summary>
        /// <returns>回傳全部使用者相關資料</returns>
        public DataTable QueryUserByID(string strUserID)
        {
            try
            {
                strSQL = "Select * From WebUser Where UserID ='" + strUserID + "'";
                return new CommonFun().GenDataTable(strSQL);
            }
            catch (Exception ex)
            {
                new CommonFun().AddErrorMsg("QueryUserByID", ex.ToString(), strSQL);
                return null;
            }
        }
        #endregion

        #region public DataTable QueryUsersBySiteID(string strSiteID)        //查詢案場告警使用者清單
        /// <summary>
        /// 查詢案場告警使用者清單 
        /// </summary>
        /// <returns>回傳案場告警使用者清單相關資料</returns>
        public DataTable QueryUsersBySiteID(string strSiteID)
        {
            try
            {
                strSQL = "SELECT U.UserID, U.UserName";
                strSQL = strSQL + " FROM Web_UserRight R, WebUser U";
                strSQL = strSQL + " where R.userid=U.userid and R.SiteID='" + strSiteID + "' and R.Role <>'9'";
                return new CommonFun().GenDataTable(strSQL);
            }
            catch (Exception ex)
            {
                new CommonFun().AddErrorMsg("QueryUsersBySiteID", ex.ToString(), strSQL);
                return null;
            }
        }
        #endregion

        #region public DataTable UserAuth(string UserID, string PW)      //確認使用者資料    By Victor
        /// <summary>
        /// 使用者認證
        /// </summary>
        /// <param name="UserID">員工帳號</param>
        /// <param name="PW">密碼</param>
        /// <returns>回傳正確與否</returns>
        public DataTable UserAuth(string UserID, string PW)
        {
            try
            {
                strSQL = "Select * From WebUser Where UserID ='" + UserID + "' and UserPassword ='" + PW + "'";
                dtTemp = new CommonFun().GenDataTable(strSQL);
                if (dtTemp.Rows.Count > 0)
                {
                    return dtTemp;
                }
                else
                {
                    return null;
                }
            }
            catch(Exception ex)
            {
                new CommonFun().AddErrorMsg("UserAuth", ex.ToString(), strSQL);
                return null;
            }
        }
        #endregion

        #region public bool AddWebUser       //新增網頁使用者        By Victor
        /// <summary>
        /// 新增網頁使用者
        /// </summary>
        /// <param name="UserID">使用者帳號</param>
        /// <param name="UserPassword">使用者密碼</param>
        /// <param name="UserName">使用者姓名</param>
        /// <param name="Email">使用者Email</param>
        /// <param name="MobileTel">使用者手機號碼</param>
        /// <param name="OfficeTel">辦公室電話</param>
        /// <param name="SysAdmin">是否為系統管理者</param>
        /// <param name="StartDate">帳號開通日</param>
        /// <param name="DueDate">帳號到期日</param>
        /// <param name="Locked">是否鎖定</param>
        /// <param name="Note">說明</param>
        /// <param name="ModifyUserID">修改者帳號</param>
        /// <returns>新增成功與否</returns>
        public bool AddWebUser(string UserID, string UserPassword, string UserName, string Email, string MobileTel, string OfficeTel, string SysAdmin, DateTime StartDate, DateTime? DueDate, string Locked, string Note, string ModifyUserID)
        {
            try
            {
                string strStartDate = StartDate.ToString("yyyy/MM/dd HH:mm:ss");
                string ApplyTime = strUpdateTime;
                if (DueDate.HasValue)
                {
                    string strDueDate = DueDate.Value.ToString("yyyy/MM/dd HH:mm:ss");
                    strSQL = " Insert Into WebUser(UserID, UserPassword, UserName, Email, MobileTel, OfficeTel, SysAdmin, StartDate, DueDate, Locked, Note, ApplyTime, ModifyUserID) ";
                    strSQL += " Values('" + UserID + "','" + UserPassword + "','" + UserName + "','" + Email + "','" + MobileTel + "','" + OfficeTel + "','" + SysAdmin + "','" + strStartDate + "','" + strDueDate + "','" + Locked + "','" + Note + "','" + ApplyTime + "','" + ModifyUserID + "')";
                }
                else
                {
                    strSQL = " Insert Into WebUser(UserID, UserPassword, UserName, Email, MobileTel, OfficeTel, SysAdmin, StartDate, DueDate, Locked, Note, ApplyTime, ModifyUserID) ";
                    strSQL += " Values('" + UserID + "','" + UserPassword + "','" + UserName + "','" + Email + "','" + MobileTel + "','" + OfficeTel + "','" + SysAdmin + "','" + strStartDate + "', null,'" + Locked + "','" + Note + "','" + ApplyTime + "','" + ModifyUserID + "')";
                }
                return new CommonFun ().ExeSQL(strSQL);
            }
            catch(Exception ex)
            {
                new CommonFun().AddErrorMsg("AddWebUser", ex.ToString(), strSQL);
                return false;
            }
        }
        #endregion

        #region public bool UpdateWebUser       //修改使用者資料        By Victor
        /// <summary>
        /// 修改網頁使用者
        /// </summary>
        /// <param name="UserID">使用者帳號</param>
        /// <param name="UserPassword">使用者密碼</param>
        /// <param name="UserName">使用者姓名</param>
        /// <param name="Email">使用者Email</param>
        /// <param name="MobileTel">使用者手機號碼</param>
        /// <param name="OfficeTel">辦公室電話</param>
        /// <param name="SysAdmin">是否為系統管理者</param>
        /// <param name="StartDate">帳號開通日</param>
        /// <param name="DueDate">帳號到期日</param>
        /// <param name="Locked">是否鎖定</param>
        /// <param name="Note">說明</param>
        /// <param name="ModifyUserID">修改者帳號</param>
        /// <returns>修改成功與否</returns>
        public bool UpdateWebUser(string UserID, string UserPassword, string UserName, string Email, string MobileTel, string OfficeTel, string SysAdmin, DateTime StartDate, DateTime? DueDate, string Locked, string Note, string ModifyUserID)
        {
            try
            {
                string strStartDate = StartDate.ToString("yyyy/MM/dd HH:mm:ss");
                string ApplyTime = strUpdateTime;
                if (DueDate.HasValue)
                {
                    string strDueDate = DueDate.Value.ToString("yyyy/MM/dd HH:mm:ss");
                    strSQL = " Update WebUser Set UserPassword='" + UserPassword + "',  UserName='" + UserName + "',  Email='" + Email + "', MobileTel='" + MobileTel + "', OfficeTel='" + OfficeTel + "', SysAdmin='" + SysAdmin + "', StartDate='" + strStartDate + "', DueDate='" + strDueDate + "', Locked='" + Locked + "', Note='" + Note + "', ModifyUserID='" + ModifyUserID + "' ";
                    strSQL += " Where UserID ='" + UserID + "'";                    
                }
                else
                {
                    strSQL = " Update WebUser Set UserPassword='" + UserPassword + "',  UserName='" + UserName + "',  Email='" + Email + "', MobileTel='" + MobileTel + "', OfficeTel='" + OfficeTel + "', SysAdmin='" + SysAdmin + "', StartDate='" + strStartDate + "', DueDate=null, Locked='" + Locked + "', Note='" + Note + "', ModifyUserID='" + ModifyUserID + "' ";
                    strSQL += " Where UserID ='" + UserID + "'";  
                }

                return new CommonFun ().ExeSQL(strSQL);
            }
            catch(Exception ex)
            {
                new CommonFun().AddErrorMsg("UpdateWebUser", ex.ToString(), strSQL);
                return false;
            }
        }
        #endregion

        #region public bool DelWebUser       //刪除使用者資料       By Victor
        /// <summary>
        /// 刪除網頁使用者
        /// </summary>
        /// <returns>刪除成功與否</returns>
        public bool DelWebUser(string UserID)
        {
            try
            {
                strSQL = "Begin TRAN ";
                //MPLCConfig_cfg
                strSQL += " Update MPLCConfig_cfg Set bytSMSEmpNo = '0'  Where bytSMSEmpNo = '" + UserID + "'";                                                         //  1
                strSQL += " Update MPLCConfig_cfg Set bytSMSEmpNo = Replace(bytSMSEmpNo , '," + UserID + ",', ',') Where bytSMSEmpNo Like '%," + UserID + ",%'";      // ,1, 
                strSQL += " Update MPLCConfig_cfg Set bytSMSEmpNo = Replace(bytSMSEmpNo , '," + UserID + "', '') Where bytSMSEmpNo Like '%," + UserID + "'";          //  x,1       
                strSQL += " Update MPLCConfig_cfg Set bytSMSEmpNo = Replace(bytSMSEmpNo , '" + UserID + ",', '') Where bytSMSEmpNo Like '" + UserID + ",%'";          //  1,x 

                strSQL += " Update MPLCConfig_cfg Set byteMailEmpNo = '0'  Where byteMailEmpNo = '" + UserID + "'";                                                           //  1
                strSQL += " Update MPLCConfig_cfg Set byteMailEmpNo = Replace(byteMailEmpNo , '," + UserID + ",', ',') Where byteMailEmpNo Like '%," + UserID + ",%'";      // ,1, 
                strSQL += " Update MPLCConfig_cfg Set byteMailEmpNo = Replace(byteMailEmpNo , '," + UserID + "', '') Where byteMailEmpNo Like '%," + UserID + "'";          //  x,1       
                strSQL += " Update MPLCConfig_cfg Set byteMailEmpNo = Replace(byteMailEmpNo , '" + UserID + ",', '') Where byteMailEmpNo Like '" + UserID + ",%'";          //  1,x 

                //DevConfig_cfg
                strSQL += " Update DevConfig_cfg Set bytSMSEmpNo = '0'  Where bytSMSEmpNo = '" + UserID + "'";                                                         //  1
                strSQL += " Update DevConfig_cfg Set bytSMSEmpNo = Replace(bytSMSEmpNo , '," + UserID + ",', ',') Where bytSMSEmpNo Like '%," + UserID + ",%'";      // ,1, 
                strSQL += " Update DevConfig_cfg Set bytSMSEmpNo = Replace(bytSMSEmpNo , '," + UserID + "', '') Where bytSMSEmpNo Like '%," + UserID + "'";          //  x,1       
                strSQL += " Update DevConfig_cfg Set bytSMSEmpNo = Replace(bytSMSEmpNo , '" + UserID + ",', '') Where bytSMSEmpNo Like '" + UserID + ",%'";          //  1,x 

                strSQL += " Update DevConfig_cfg Set byteMailEmpNo = '0'  Where byteMailEmpNo = '" + UserID + "'";                                                           //  1
                strSQL += " Update DevConfig_cfg Set byteMailEmpNo = Replace(byteMailEmpNo , '," + UserID + ",', ',') Where byteMailEmpNo Like '%," + UserID + ",%'";      // ,1, 
                strSQL += " Update DevConfig_cfg Set byteMailEmpNo = Replace(byteMailEmpNo , '," + UserID + "', '') Where byteMailEmpNo Like '%," + UserID + "'";          //  x,1       
                strSQL += " Update DevConfig_cfg Set byteMailEmpNo = Replace(byteMailEmpNo , '" + UserID + ",', '') Where byteMailEmpNo Like '" + UserID + ",%'";          //  1,x 

                //TagConfig_cfg
                strSQL += " Update TagConfig_cfg Set bytSMSEmpNo = '0'  Where bytSMSEmpNo = '" + UserID + "'";                                                         //  1
                strSQL += " Update TagConfig_cfg Set bytSMSEmpNo = Replace(bytSMSEmpNo , '," + UserID + ",', ',') Where bytSMSEmpNo Like '%," + UserID + ",%'";      // ,1, 
                strSQL += " Update TagConfig_cfg Set bytSMSEmpNo = Replace(bytSMSEmpNo , '," + UserID + "', '') Where bytSMSEmpNo Like '%," + UserID + "'";          //  x,1       
                strSQL += " Update TagConfig_cfg Set bytSMSEmpNo = Replace(bytSMSEmpNo , '" + UserID + ",', '') Where bytSMSEmpNo Like '" + UserID + ",%'";          //  1,x 

                strSQL += " Update TagConfig_cfg Set byteMailEmpNo = '0'  Where byteMailEmpNo = '" + UserID + "'";                                                           //  1
                strSQL += " Update TagConfig_cfg Set byteMailEmpNo = Replace(byteMailEmpNo , '," + UserID + ",', ',') Where byteMailEmpNo Like '%," + UserID + ",%'";      // ,1, 
                strSQL += " Update TagConfig_cfg Set byteMailEmpNo = Replace(byteMailEmpNo , '," + UserID + "', '') Where byteMailEmpNo Like '%," + UserID + "'";          //  x,1       
                strSQL += " Update TagConfig_cfg Set byteMailEmpNo = Replace(byteMailEmpNo , '" + UserID + ",', '') Where byteMailEmpNo Like '" + UserID + ",%'";          //  1,x 

                //Web_MeterConfig
                //strSQL += " Update Web_MeterConfig Set SMSEmpNo = '0'  Where SMSEmpNo = '" + EmpNo + "'";                                                        //  1
                //strSQL += " Update Web_MeterConfig Set SMSEmpNo = Replace(SMSEmpNo , '," + EmpNo + ",', ',') Where SMSEmpNo Like '%," + EmpNo + ",%'";        // ,1, 
                //strSQL += " Update Web_MeterConfig Set SMSEmpNo = Replace(SMSEmpNo , '," + EmpNo + "', '') Where SMSEmpNo Like '%," + EmpNo + "'";            //  x,1       
                //strSQL += " Update Web_MeterConfig Set SMSEmpNo = Replace(SMSEmpNo , '" + EmpNo + ",', '') Where SMSEmpNo Like '" + EmpNo + ",%'";            //  1,x 

                //strSQL += " Update Web_MeterConfig Set EmailEmpNo = '0'  Where EmailEmpNo = '" + EmpNo + "'";                                                          //  1
                //strSQL += " Update Web_MeterConfig Set EmailEmpNo = Replace(EmailEmpNo , '," + EmpNo + ",', ',') Where EmailEmpNo Like '%," + EmpNo + ",%'";        // ,1, 
                //strSQL += " Update Web_MeterConfig Set EmailEmpNo = Replace(EmailEmpNo , '," + EmpNo + "', '') Where EmailEmpNo Like '%," + EmpNo + "'";            //  x,1       
                //strSQL += " Update Web_MeterConfig Set EmailEmpNo = Replace(EmailEmpNo , '" + EmpNo + ",', '') Where EmailEmpNo Like '" + EmpNo + ",%'";            //  1,x 

                ////Web_MeterVGrpConfig
                //strSQL += " Update Web_MeterVGrpConfig Set SMSEmpNo = '0'  Where SMSEmpNo = '" + EmpNo + "'";                                                        //  1
                //strSQL += " Update Web_MeterVGrpConfig Set SMSEmpNo = Replace(SMSEmpNo , '," + EmpNo + ",', ',') Where SMSEmpNo Like '%," + EmpNo + ",%'";        // ,1, 
                //strSQL += " Update Web_MeterVGrpConfig Set SMSEmpNo = Replace(SMSEmpNo , '," + EmpNo + "', '') Where SMSEmpNo Like '%," + EmpNo + "'";            //  x,1       
                //strSQL += " Update Web_MeterVGrpConfig Set SMSEmpNo = Replace(SMSEmpNo , '" + EmpNo + ",', '') Where SMSEmpNo Like '" + EmpNo + ",%'";            //  1,x 

                //strSQL += " Update Web_MeterVGrpConfig Set EmailEmpNo = '0'  Where EmailEmpNo = '" + EmpNo + "'";                                                          //  1
                //strSQL += " Update Web_MeterVGrpConfig Set EmailEmpNo = Replace(EmailEmpNo , '," + EmpNo + ",', ',') Where EmailEmpNo Like '%," + EmpNo + ",%'";        // ,1, 
                //strSQL += " Update Web_MeterVGrpConfig Set EmailEmpNo = Replace(EmailEmpNo , '," + EmpNo + "', '') Where EmailEmpNo Like '%," + EmpNo + "'";            //  x,1       
                //strSQL += " Update Web_MeterVGrpConfig Set EmailEmpNo = Replace(EmailEmpNo , '" + EmpNo + ",', '') Where EmailEmpNo Like '" + EmpNo + ",%'";            //  1,x 

                //WebAlarmConfig
                strSQL += " Delete From WebAlarmConfig Where UserID = '" + UserID + "'";

                //Web_UserRight
                strSQL += " Delete From Web_UserRight Where UserID = '" + UserID + "'";
                
                //實際Delete WebUser
                strSQL += " Delete From WebUser Where UserID ='" + UserID + "'";

                //MsgPipe_data
                strSQL += " Update MsgPipe_data Set bytIsRenew ='1', UpdateTime ='" + strUpdateTime + "' Where strTableName = 'MPLCConfig_cfg'";
                strSQL += " Update MsgPipe_data Set bytIsRenew ='1', UpdateTime ='" + strUpdateTime + "' Where strTableName = 'DevConfig_cfg'";
                strSQL += " Update MsgPipe_data Set bytIsRenew ='1', UpdateTime ='" + strUpdateTime + "' Where strTableName = 'TagConfig_cfg'";
                //strSQL += " Update MsgPipe_data Set bytIsRenew ='1', UpdateTime ='" + strUpdateTime + "' Where strTableName = 'Web_MeterConfig'";
                //strSQL += " Update MsgPipe_data Set bytIsRenew ='1', UpdateTime ='" + strUpdateTime + "' Where strTableName = 'Web_MeterVGrpConfig'";
                strSQL += " Update MsgPipe_data Set bytIsRenew ='1', UpdateTime ='" + strUpdateTime + "' Where strTableName = 'WebAlarmConfig'";
                strSQL += " Update MsgPipe_data Set bytIsRenew ='1', UpdateTime ='" + strUpdateTime + "' Where strTableName = 'WebUser'";

                strSQL += " IF @@ERROR = 0";
                strSQL += " COMMIT TRAN ";
                strSQL += " Else ";
                strSQL += " RollBack TRAN ";

                bool bExe = new CommonFun().ExeSQL(strSQL);
                strSQL = "Select * From WebUser Where UserID = '" + UserID + "'";
                dtTemp = new CommonFun().GenDataTable(strSQL);

                if (bExe && dtTemp .Rows .Count == 0)
                {
                    return true;
                }
                else
                {
                    return false;
                }
            }
            catch (Exception ex)
            {
                new CommonFun().AddErrorMsg("DelWebUser", ex.ToString(), strSQL);
                return false;
            }
        }
        #endregion

        //系統記錄      相關Table：Web_SysLog       By Victor
        #region public enum eEventType : int
        public enum eEventType : int
        {
            嚴重 = 1,                       
            重要 = 2,                       
            一般 = 3,                        
            登入成功 = 10,                    
            登入失敗 = 11,                      
            登出 = 21,                        
            未知 = 99
        }
        #endregion

        #region public string GetEventTypeString
        public string GetEventTypeString(int iEventType)
        {
            string strEventTypeString = "";
            switch (iEventType)
            {
                case 1:
                    strEventTypeString = "嚴重";
                    break;
                case 2:
                    strEventTypeString = "重要";
                    break;
                case 3:
                    strEventTypeString = "一般";
                    break;
                case 10:
                    strEventTypeString = "登入成功";
                    break;
                case 11:
                    strEventTypeString = "登入失敗";
                    break;
                case 21:
                    strEventTypeString = "登出";
                    break;
                case 99:
                    strEventTypeString = "未知";
                    break;

            }
            return strEventTypeString;
        }
        #endregion

        #region public bool AddSysLog(string SiteID, string UserID, string LoginIP, string EventType, string EventMemo)     //記錄使用者操作紀錄
        /// <summary>
        /// 記錄使用者操作紀錄
        /// </summary>
        /// <param name="SiteID">案場ID</param>
        /// <param name="UserID">操作者ID</param>
        /// <param name="LoginIP">登入IP</param>
        /// <param name="EventType">事件型態（『嚴重』、『重要』、『一般』、『登入成功』、『登入失敗』、『登出』）</param>
        /// <param name="EventMemo">訊息記錄</param>
        /// <returns>回傳記錄成功與否</returns>
        public bool AddSysLog(string SiteID, string UserID, string LoginIP, string EventType, string EventMemo)
        {
            try
            {
                strSQL = " INSERT INTO Web_SysLog (SiteID, UserID, LoginIP, EventType, EventMemo)";
                strSQL += " Values ('" + SiteID + "','" + UserID + "','" + LoginIP + "','" + EventType + "','" + EventMemo + "')";

                return new CommonFun().ExeSQL(strSQL);
            }
            catch(Exception ex)
            {
                new CommonFun().AddErrorMsg("AddSysLog", ex.ToString(), strSQL);
                return false;
            }
        }
        #endregion


        //使用者權限設定        相關Table：Web_UserRight        By Victor
        #region public bool AddUserRight        //新增使用者權限
        /// <summary>
        /// 新增使用者權限
        /// </summary>
        /// <param name="UserID">使用者帳號</param>
        /// <param name="SiteID">案場代號</param>
        /// <param name="Role">身份權限</param>
        /// <param name="ModifyUserID">修改者帳號</param>
        /// <returns>回傳新增成功與否</returns>
        public bool AddUserRight(string UserID, string SiteID, string Role, string ModifyUserID)        //新增使用者權限
        {
            try
            {
                strSQL = " Insert Into Web_UserRight(UserID, SiteID, Role, ModifyUserID) ";
                strSQL += " Values('" + UserID + "','" + SiteID + "','" + Role + "','" + ModifyUserID + "')";
                return new CommonFun ().ExeSQL(strSQL);
            }
            catch (Exception ex)
            {
                new CommonFun().AddErrorMsg("AddUserRight", ex.ToString(), strSQL);
                return false;
            }
        }
        #endregion

        #region public bool UpdateUserRight        //更新使用者權限
        /// <summary>
        /// 更新使用者權限
        /// </summary>
        /// <param name="UserID">使用者帳號</param>
        /// <param name="SiteID">案場代號</param>
        /// <param name="Role">身份權限</param>
        /// <param name="ModifyUserID">修改者帳號</param>
        /// <returns>回傳更新成功與否</returns>
        public bool UpdateUserRight(string UserID, string SiteID, string Role, string ModifyUserID)        //新增使用者權限
        {
            try
            {
                strSQL = " Update Web_UserRight Set Role ='" + Role + "', ModifyUserID='" + ModifyUserID + "' Where UserID ='" + UserID + "' and SiteID ='" + SiteID + "'";
                return new CommonFun().ExeSQL(strSQL);
            }
            catch (Exception ex)
            {
                new CommonFun().AddErrorMsg("UpdateUserRight", ex.ToString(), strSQL);
                return false;
            }
        }
        #endregion

        #region public bool DelUserRight      //刪除使用者權限
        /// <summary>
        /// 刪除使用者權限
        /// </summary>
        /// <param name="UserID">使用者帳號</param>
        /// <param name="SiteID">案場代號</param>
        /// <returns>回傳刪除成功與否</returns>
        public bool DelUserRight(string UserID, string SiteID)      //刪除使用者權限
        {
            try
            {
                strSQL = " Delete From Web_UserRight Where UserID = '" + UserID + "' and SiteID = '" + SiteID + "'";
                return new CommonFun().ExeSQL(strSQL);
            }
            catch (Exception ex)
            {
                new CommonFun().AddErrorMsg("DelUserRight", ex.ToString(), strSQL);
                return false;
            }
        }
        #endregion

        #region public DataTable ShowUserRole(string UserID)      //顯示使用者所有案場權限資料    By Victor
        /// <summary>
        /// 顯示使用者所有案場權限資料（若無權限則顯示0）
        /// </summary>
        /// <param name="UserID">使用者ID</param>
        /// <returns>顯示使用者所有案場權限資料（若無權限則顯示0）</returns>
        public DataTable ShowUserRole(string UserID)
        {
            try
            {
                strSQL = "Select '" + UserID + "' as UserID, b.SiteID as SiteID, Case  When a.Role is null Then '0' else a.Role End as Role ";
                strSQL += " From (Select * From Web_UserRight where UserID ='" + UserID + "') as a Right Join Web_Site as b On a.SiteID = b.SiteID ";
                dtTemp = new CommonFun().GenDataTable(strSQL);
                if (dtTemp.Rows.Count > 0)
                {
                    return dtTemp;
                }
                else
                {
                    return null;
                }
            }
            catch (Exception ex)
            {
                new CommonFun().AddErrorMsg("ShowUserRole", ex.ToString(), strSQL);
                return null;
            }
        }
        #endregion

    }
}

